# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        博智科技  
# Name:         bd_requests
# Description:
# Author:       yzl
# Date:         2019-02-11
#-------------------------------------------------------------------------------

import requests
import re

def str2headers(file):
    headerDicts = {}
    f = open(file,'r')
    headerText = f.read()
    headers = re.split('\n',headerText)
    for header in headers:
        ret = re.split(':',header,maxsplit=1)
        headerDicts[ret[0]] = ret[1]

    return headerDicts

# headsdict = str2headers('headers.txt')
# print(headsdict)
url = 'https://www.baidu.com/s'
params = {'wd':'株洲it培训'}
headerdict = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
    'Accept-Encoding': 'gzip, deflate, br',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
    'Cache-Control': 'max-age=0',
    'Connection': 'keep-alive',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'
}

r = requests.get(url,params=params,headers=headerdict)
print(r.text)

